package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ Description: TODO
 * @ BelongsProject: zzyl
 * @ Author: G攀
 * @ CreateTime: 2024-08-25  14:52
 * @ Version: 1.0
 */
@Service
@Slf4j
public class NursingLevelServiceImpl implements NursingLevelService {

    @Autowired
    private NursingLevelMapper nursingLevelMapper;

    /**
     * 查询所有的护理等级
     */
    @Override
    public List<NursingLevelVo> getAll() {
        return nursingLevelMapper.getAll();
    }

    /**
     * 根据ID查询护理等级
     */
    @Override
    public NursingLevelVo getNursingLevelById(Long id) {
        return nursingLevelMapper.getLevelById(id);
    }

    /**
     * 修改护理等级
     */
    @Override
    public void update(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = BeanUtil.copyProperties(nursingLevelDto, NursingLevel.class);

        nursingLevelMapper.update(nursingLevel);
    }

    /**
     * 根据ID删除护理等级
     */
    @Override
    public void delete(Long id) {
        nursingLevelMapper.delete(id);
    }

    /**
     * 获取所有的护理等级信息
     *
     * @return
     */
    @Override
    public List<NursingLevel> getAllNursingLevel() {
        return nursingLevelMapper.getAllNursingLevel();
    }

    /**
     * 添加护理等级信息
     *
     * @param nursingLevelDto
     * @return
     */
    @Override
    public void addNursingLevelInfo(NursingLevelDto nursingLevelDto) {
        //1.类型转换
        NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        //2.数据补充
        nursingLevelMapper.addNursingLevelInfo(nursingLevel);
    }

    /**
     * 分页查询项目等级信息
     *
     * @param pageNum
     * @param pageSize
     * @param name
     * @param status
     * @return
     */
    @Override
    public PageResponse<NursingLevelVo> getNursingLevelByPage(Integer pageNum, Integer pageSize, String name, Integer status) {
        PageHelper.startPage(pageNum, pageSize);
        Page<NursingLevelVo> page = nursingLevelMapper.getNursingLevelByPage(name, status);
        PageResponse<NursingLevelVo> nursingLevelPageResponse = new PageResponse<>(page);
        nursingLevelPageResponse.setRecords(page.getResult());
        return nursingLevelPageResponse;
    }

    /**
     * 根据ID启用或者禁用护理等级
     */
    @Override
    public void startOrStop(Long id, Integer status) {
        // 封装护理级别对象
        NursingLevel nursingLevel = new NursingLevel();
        nursingLevel.setId(id);
        nursingLevel.setStatus(status);
        // 调用更新接口来更新数据库
        nursingLevelMapper.update(nursingLevel);
    }

}
